﻿using Microsoft.Ajax.Utilities;
using Project.API.Models;
using Project.BLL;
using Project.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Security.Cryptography;
using System.Web.Http;

namespace Project.API.Controllers
{
    public class DDmanageDetailController : ApiController
    {
        // GET: api/DDmanageDetail
        [Route("api/DDmanageDetailGET/{id}")]
        public ResultData<List<DDmanageDetailDto>> GetDDmanageDetail(int id)
        {
            int count = 0;
            var list = new DDmanageDetailBll().Query();
            var dat = list.Where(r => r.Dgdetail_id ==id);
            var data = from r in dat
                       select new DDmanageDetailDto
                       {
                           detail_id = r.detail_id,
                           id = r.id,
                           Dgdetail_id = r.Dgdetail_id,
                           number = r.number,
                           props_text = r.props_text,
                           price = r.price,
                           name=r.Goods.name,
                           gid=r.Goods.gId
                       };
            ResultData<List<DDmanageDetailDto>> result = new ResultData<List<DDmanageDetailDto>>();
            result.code = 0;
            result.msg = "ok";
            result.data = data.ToList();

            return result;
        }

        [Route("Api/CX")]
        public ResultData<List<DDmanageDetailDto>> Get(int id)
        {
            var lists = new DDmanageDetailBll().Query();
            var list = lists.Where(u => u.Dgdetail_id == id);
            var data = from r in list
                       select new DDmanageDetailDto
                       {
                           detail_id = r.detail_id,
                           //Dgdetail_id = r.Dgdetail_id,
                           name = r.Goods.name,
                           quantity = r.number,
                           unit_price = r.price,
                           specification = r.props_text,
                       };


            ResultData<List<DDmanageDetailDto>> result = new ResultData<List<DDmanageDetailDto>>();
            result.code = 0;
            result.msg = "ok";
            result.data = data.ToList();

            return result;
        }

        // POST: api/DDmanageDetail
        public Result Post([FromBody] List<DDmanageDetail> value)
        {
            bool bol = new DDmanageDetailBll().Adds(value);

            Result result = new Result();
            result.code = bol ? 1 : 0;
            result.msg = bol ? "添加成功！" : "error";
            return result;
        }

        // PUT: api/DDmanageDetail/5
        public void Put(int id, [FromBody]string value)
        {
        }

        // DELETE: api/DDmanageDetail/5
        public void Delete(int id)
        {
        }
    }
}
